<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 * $Id: 2018-03-02 17:14:35 apple $
 UC会员整合
*/
namespace core;
defined('BY_JYA') or exit('error');
class uc_member{
	public function uc_config(){
		$jy_ucenter=cfc('core')->plugin_exists('jy_ucenter');
		if(!$jy_ucenter){
			return false;
		}
		$config=plugin('jy_ucenter')->plugin_setting('basic');
		if(!$config || !$config['status']){
			return false;
		}
		if(!$config['status']){
			return false;
		}
		$params=array('db_host','db_user','db_passwd','db_name','db_pre','db_charset','api_appid');
		foreach($params as $row){
			if(!$config[$row]){
				return false;
			}
		}
		define('UC_CONNECT', 'mysql');
		define('UC_DBHOST', $config['db_host']);
		define('UC_DBUSER', $config['db_user']);
		define('UC_DBPW', $config['db_passwd']);
		define('UC_DBNAME', $config['db_name']);
		define('UC_DBCHARSET', $config['db_charset']);
		define('UC_DBTABLEPRE', $config['db_name'].'.'.$config['db_pre']);
		define('UC_KEY', $config['api_key']);
		define('UC_API', $config['api_url']);
		define('UC_CHARSET', $config['api_charset']);
		define('UC_IP', $config['api_ip']);
		define('UC_APPID', $config['api_appid']);
		require_once ROOT_D.'/core/library/uc/include/db_mysql.class.php';
		require_once ROOT_D.'/core/library/uc/uc_client/client.php';
		return true;
	}
	public function uc_login($username,$password){
		if(!$this->uc_config()){
			return false;
		}
		$result=uc_user_login($username,$password);
		if($result && $result['0']>0){
			return true;
		}
		return false;
	}
	public function uc_register($username,$password,$email='',$mid=0){
		if(!$this->uc_config()){
			return false;
		}
		$result=uc_user_register($username,$password,$email);
		if($result && $result['0']>0){
			$insert=array(
				'uniacid'=>$_SESSION['uniacid'],
				'type'=>12,
				'openid'=>$result['0'],
				'nickname'=>$username,
				'createtime'=>TIMESTAMP,
			);
			$insert['mid']=$mid;
			pdo_insert('core_fans',$insert);
			return true;
		}
		return false;
	}
}